package com.example.review.service.impl;

import com.example.review.entity.UserInfo;
import com.example.review.service.ReviewService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReviewServiceImpl implements ReviewService {

    @Override
    public String day1(String str) {
        if (str.isEmpty()) {
            str = "there is Hall";
        }
        return str;
    }

    @Override
    public String huiWen(String str) {
        char[] strArr = str.toCharArray();
        if (strArr.length > 1) {
            for (int i = 0; i < strArr.length; i++) {
                if (i >= strArr.length - i - 1) {
                    break;
                }
                if (strArr[i] != strArr[strArr.length - i - 1]) {
                    return "[" + str + "] 不是回文字符串";
                }
            }
        }
        return "[" + str + "] 是回文字符串";
    }

    @Override
    public List<Integer> getTheNum(Integer[] intArr) {
        int n = intArr.length;
        for (int i = 0; i < n - 1; i++) {
            boolean swapped = false; // 标记是否发生交换
            for (int j = 0; j < n - 1 - i; j++) {  // 内层循环的范围优化
                if (intArr[j] > intArr[j + 1]) {
                    Integer temp = intArr[j + 1];
                    intArr[j + 1] = intArr[j];
                    intArr[j] = temp;
                    swapped = true;
                }
            }
            if (!swapped) { // 如果没有发生交换，提前结束
                break;
            }
        }
        List<Integer> iList = new ArrayList<>();
        iList.add(intArr[0]);  // 最小值
        iList.add(intArr[n - 1]);  // 最大值
        return iList;
    }

    @Override
    public String getTheNum1(Integer[] intArr) {
        Integer maxNum = intArr[0];
        Integer minNum = intArr[0];

        for (Integer curNum : intArr) {
            if (curNum > maxNum) {
                maxNum = curNum;
            }
            if (curNum < minNum) {
                minNum = curNum;
            }
        }
        System.out.println(minNum + "," + maxNum);
        return minNum + "," + maxNum;
    }

    @Override
    public UserInfo getUserInfo() {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId("1");
        userInfo.setUserName("影魔");
        userInfo.setAge(100);
        userInfo.setPhone("xxxxxx");
        userInfo.setSex(Boolean.TRUE);
        return userInfo;
    }
}
